package com.tlgen.orm.components.rest;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

public class RestFactoryBean<T> implements FactoryBean<T> {

    private Class<T> restInterface;

    public void setRestInterface(Class<T> restInterface) {
        this.restInterface = restInterface;
    }

    public RestFactoryBean() {
        this.restInterface = restInterface;
    }

    @Override
    public T getObject() throws Exception {
        return (T) Proxy.newProxyInstance(restInterface.getClassLoader(),
                new Class[]{restInterface}, new RestProxy<T>(restInterface));
    }

    @Override
    public Class<?> getObjectType() {
        return this.restInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

}
